﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using Microsoft.Practices.Unity;
using System.Web.WebPages;


namespace Local
{
    public static class WebExtn
    {
        public static bool IsWebAdmin(this WebPageExecutingBase page)
        {
            bool webadmin = false;
            try
            {
                webadmin = page.Context.Request.IsLocal
                    || (page.Context.Request.IsAuthenticated
                        && page.Context.User.IsInRole("webadmin"));
            }
            catch (Exception csx)
            {
                //try
                //{
                //    WebSecurityInitializer.Instance.EnsureInitialize();
                //    webadmin = page.Context.Request.IsLocal
                //        || (page.Context.Request.IsAuthenticated
                //        && page.Context.User.IsInRole("webadmin"));

                //}
                //catch
                //{
                //}
            }
            return webadmin;
        }
        public static bool IsWebAdmin(this Controller page)
        {
            bool webadmin = false;
            try
            {
                webadmin = page.Request.IsLocal
                    || (page.Request.IsAuthenticated
                        && page.User.IsInRole("webadmin"));
            }
            catch (Exception cx)
            {
                try
                {
                   
                        webadmin = page.Request.IsLocal
                                || (page.Request.IsAuthenticated
                                && page.User.IsInRole("webadmin"));
                    

                }
                catch
                {
                }
            }
            return webadmin;
        }
        public static string GetLocalLink(string id)
        {
            string url = System.Configuration.ConfigurationManager.AppSettings["LocalLink"];
            return url;
        }
        public static string GetValueFromKey(string id)
        {
            string good = System.Configuration.ConfigurationManager.AppSettings[id];
            return good;
        }
        public static string Link(this UrlHelper url, string relativePath)
        {
            string path = url.Content(relativePath);
            if (path.StartsWith("http"))
            {
                return path;
            }
            else
            {
                return "MvcApplication.ApplicationPath" + path;
            }
        }
      
       
    }
}